package com.ruoyi.act.module.api;

import com.ruoyi.act.module.domain.ActModel;
import com.ruoyi.act.module.service.IModelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.activiti.engine.repository.Model;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 工作流租户对象 act_biz_info
 *
 * @author hcj
 * @date 2020-12-24
 */
@RestController
@RequestMapping("/api/model")
public class ApiModelController extends BaseController {

    @Autowired
    private IModelService iModelService;

    /**
     * 获取流程信息
     *
     * @param actModel
     * @return
     */
    @PostMapping("/info")
    public AjaxResult info(@RequestBody ActModel actModel) {
        List<Model> list = iModelService.findList(actModel);
        List<Map<String, Object>> list1 = new ArrayList<>();

        list.forEach(model -> {
            Map<String, Object> map = new HashMap<>();
            map.put("id", model.getId());
            map.put("name", model.getName());
            map.put("tenantId", model.getTenantId());
            map.put("image", "data:image/png;base64," + Base64.encodeBase64String(iModelService.getEditorSource(model.getId())));
            list1.add(map);
        });
        return AjaxResult.success(list1);
    }

}
